package com.cqupt.scanning.system.admin.controller;


import cn.hutool.core.util.StrUtil;
import com.cqupt.scanning.system.acl.entity.dto.RoleGroupDTO;
import com.cqupt.scanning.system.admin.entity.vo.DeviceVO;
import com.cqupt.scanning.system.admin.service.DeviceFootService;
import com.cqupt.scanning.system.admin.service.DeviceThreeService;
import com.cqupt.scanning.system.utils.result.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 宋宝梁
 * @since 2021-07-06
 */
@RestController
@RequestMapping("/admin/organization/device")
public class DeviceIndexController {

    private DeviceFootService deviceFootService;
    private DeviceThreeService deviceThreeService;

    @Autowired
    public DeviceIndexController(DeviceFootService deviceFootService, DeviceThreeService deviceThreeService) {
        this.deviceFootService = deviceFootService;
        this.deviceThreeService = deviceThreeService;
    }

    /**
     * 新增设备(同时绑定账号)
     * @param deviceVO
     * @return
     */
    @PostMapping("/insert")
    @PreAuthorize("hasAuthority('device.insert')")
    public R insert(@RequestBody DeviceVO deviceVO) {
        String devName = deviceVO.getDevName();
        if (StrUtil.equals(devName, "步态分析")) {
            return deviceFootService.insert(deviceVO);
        } else if(StrUtil.equals(devName, "三维扫描")){
            return deviceThreeService.insert(deviceVO);
        }
        return R.error().message("设备名字不匹配");
    }

    /**
     * 修改设备
     * @param deviceVO
     * @return
     */
    @PutMapping("/update")
    public R update(@RequestBody @Validated DeviceVO deviceVO) {
        return deviceFootService.update(deviceVO);
    }
}

